package com.sun.showcase.controller.app;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.sun.showcase.biz.basic.utils.FtpClientConstants;
import com.sun.showcase.utils.FileUpload;
import com.sun.showcase.utils.SpringApplicationContextHolder;

@Controller
@RequestMapping(value="/app/mytools") 
public class MyToolsController {
	
	@RequestMapping(value="/upload")
	@ResponseBody
	public Object upload(
			@RequestParam(required=false) MultipartFile file
			) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		FtpClientConstants ftpClientConstants=(FtpClientConstants)SpringApplicationContextHolder.getBean("ftpClientConstants");
		String imagePath = FileUpload.uploadLocal("picture", file);
		map.put("imageUrl",ftpClientConstants.getPrefixUrl()+ imagePath);
		map.put("imagePath", imagePath);
		return map;
	}

}
